/**
 * https://vitejs.dev/config/
 */
import type { ConfigEnv, UserConfig } from 'vite';
import { createVitePlugins } from './build';

import fs from 'fs-extra';
import path from 'path';
import dotenv from 'dotenv';

export default ({ command }: ConfigEnv): UserConfig => {
  const env = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), './.env')));

  return {
    envPrefix: 'UNIAPP_',
    plugins: createVitePlugins(env, command === 'build'),
    css: {
      preprocessorOptions: {
        scss: {
          api: "modern-compiler",
          javascriptEnabled: true,
          additionalData: '@use"@/styles/index.scss" as *;',
          silenceDeprecations: ['legacy-js-api']// 关闭特定弃用警告[^3]
        }
      }
    },
   
    server: {
      host: true,
      port: 3001,
      // https: true,
      proxy: {
        '/api': {
          target: "https://test.mall.huibangtech.cn/",
          changeOrigin: true,
          secure: false,
          ws: false,
        }
      }
    }
  };
};